package com.ac.action;

import java.util.List;

import com.ac.entity.User;
import com.opensymphony.xwork2.ActionContext;


public class InstallAction extends DefaultAction{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private User user;
	
	public String execute(){
		
		
		return INPUT;
	}
	
	public String confirm(){
		
		List list =  this.getHibernateBaseDao().getAllList(User.class);
		
		if(list == null || list.size() < 1){
			//install
			user = new User();
			user.setUserName("admin");
			user.setPassword("admin");
			user.setDept(0);
			user.setAuthorityUnion("0:1:2:3:4");
			user.setApprove(1);
			
			this.getHibernateBaseDao().saveOrUpdate(user);
			return SUCCESS;
		}else{
			//
			this.addActionError("don't repeat install");
			return ERROR;
		}

		
	}
	
	public String logout(){
		
		
		ActionContext.getContext().getSession().clear();
		
		return "login";
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
}
